﻿using FlyingHat.Model.Models;
using FlyingHat.Service.IService;
using Microsoft.AspNetCore.Mvc;

namespace FlyingHat.Web.Controllers
{
    /// <summary>
    /// 分类管理
    /// </summary>
    public class ClassificationController : BaseController
    {

        private readonly IClassificationService classificationService;

        public ClassificationController(IClassificationService classificationService)
        {
            this.classificationService = classificationService;
        }

        [HttpGet]
        public IActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public async Task<IActionResult> GetTree(long spreadId = 0)
          => Json(await classificationService.GetTree(spreadId).ConfigureAwait(false));

        [HttpPost]
        public async Task<IActionResult> AddOrUpdate(ClassificationModel model)
            => Json(await classificationService.AddOrUpdate(model).ConfigureAwait(false));

        [HttpPost]
        public async Task<IActionResult> Delete(long id)
        => Json(await classificationService.Delete(id).ConfigureAwait(false));



    }
}
